<template>
  <div class="container">
    <!-- 客户信息-客户查询 -->
    <!-- 查询条件 -->
    <el-form :inline="true" class="tableSearchBox hasPrint" size="medium">
      <!-- <el-form-item label="设备类型：">
        <el-select v-model="search.meterTypeID" placeholder="请选择设备类型">
          <el-option v-for="(item,index) in devTypeList" :key="index" :label="item.meterTypeName"
            :value="item.meterTypeID">
          </el-option>
        </el-select>
      </el-form-item>
       -->
      <!-- <el-form-item label="抄表类型：">
        <el-select v-model="search.status" placeholder="请选择状态">
          <el-option v-for="(item,index) in statusList" :key="index" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="抄表员：">
        <el-select v-model="search.meterReaderID" placeholder="请选择抄表员">
          <el-option v-for="(item,index) in meterReaderList" :key="index" :label="item.name"
            :value="item.meterReaderID">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="用户编号：">
        <el-input v-model.trim="search.meterID" placeholder="请输入用户编号"
          @keyup.enter.native="tablePagination.current=1;getData()" clearable />
      </el-form-item>
      <el-form-item label="用户姓名：">
        <el-input v-model.trim="search.name" placeholder="请输入用户姓名"
          @keyup.enter.native="tablePagination.current=1;getData()" clearable />
      </el-form-item>
      <el-form-item label="手机号：">
        <el-input v-model.trim="search.phone" placeholder="请输入手机号"
          @keyup.enter.native="tablePagination.current=1;getData()" clearable />
      </el-form-item>
      <el-form-item label="户表类型：">
        <el-select v-model="search.userMeterTypeID" placeholder="请选择户表类型" clearable>
          <el-option v-for="(item,index) in userMeterTypeList" :key="index" :label="item.userMeterTypeName"
            :value="item.userMeterTypeID">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用水类型：">
        <el-select v-model="search.waterRateID" placeholder="请选择用水类型" clearable>
          <el-option v-for="(item,index) in waterRateList" :key="index" :label="item.waterRateName"
            :value="item.waterRateID">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属小区：">
        <el-select v-model="search.villageID" filterable :filter-method="villageFilter" placeholder="请输入或选择查询小区"
          clearable>
          <el-option v-for="item in userAddrList" :key="item.villageID" :label="item.villageName"
            :value="item.villageID">
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="所属册号：">
        <el-select v-model="search.volumeID" filterable placeholder="请选择册号" clearable>
          <el-option v-for="item in volumeList" :key="item.volumeID" :label="item.volumeName" :value="item.volumeID">
          </el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="行业类型：">
        <el-select v-model="search.tradeTypeID" placeholder="请选择行业类型" clearable>
          <el-option v-for="(item,index) in tradeTypeList" :key="index" :label="item.tradeTypeName"
            :value="item.tradeTypeID">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="抄表周期：">
        <el-select v-model="search.meterReadCycleID" placeholder="请选择抄表周期" clearable>
          <el-option v-for="(item,index) in cycleAmountList" :key="index" :label="item.meterReadCycleName"
            :value="item.meterReadCycleID">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="缴费类型：">
        <el-select v-model="search.costTypeID" placeholder="请选择缴费类型" clearable>
          <el-option v-for="(item,index) in costTypeList" :key="index" :label="item.costTypeName"
            :value="item.costTypeID">
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="抄表类型：">
        <el-select v-model="search.meterReadTypeID" placeholder="请选择">
          <el-option v-for="(item,index) in typeAmountList" :key="index" :label="item.meterReadTypeName"
            :value="item.meterReadTypeID">
          </el-option>
        </el-select>
      </el-form-item> -->

      <!-- <el-form-item label="时间：">
        <el-date-picker v-model="search.time" type="daterange" value-format="yyyy-MM-dd" range-separator="至"
          start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="tablePagination.current=1;getData()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- /查询条件 -->
    <PagesTable :tableMaxHeight="tableHeight" ref="child" :tableExportPrinting="true" :tableID="'customerInquire'"
      :isTableTitle="false" :tableTitle="'客户列表'" :border="true" :isIndex="true" :tableSpan="tableSpan"
      :tableHeader="tableHeader" :tableData="tableData" :tableOperation="tableOperation"
      :tablePagination="tablePagination" @pageSize="pageSizeChange" @currentPage="currentPageChange"
      @pageOperation="handlePageOperation" @getTableAllData="getTableAllData" />
    <!-- <el-table class="sanfan-table" border :data="tableData" style="width: 100%;table-layout:fixed;"
      :span-method="objectSpanMethod" :highlight-current-row="true">
      <el-table-column v-for="(item,index) in tableHeader" :key="index" :prop="item.mark"
        :label="item.unit?item.name+'('+item.unit+')':item.name" :min-width="item.minWidth" :width="item.width"
        align="center" :show-overflow-tooltip="true" :fixed="item.fixed">
        <template slot-scope="scope">
          <span v-if="item.mark"
            :class="(scope.row[item.mark]!==null&&scope.row[item.mark]!==undefined?(scope.row[item.mark].value<scope.row[item.mark].min||scope.row[item.mark].value>scope.row[item.mark].max):false)?'red':(item.color?item.color[scope.row[item.marks]]:'')">{{scope.row[item.mark]!==null&&scope.row[item.mark]!==undefined?(scope.row[item.mark].value?scope.row[item.mark].value:(item.list?item.list[scope.row[item.mark]]:(item.showList?(item.showList[scope.row[item.marks]]?scope.row[item.mark]:'-'):(item.toFixedNum?scope.row[item.mark].toFixed(item.toFixedNum):scope.row[item.mark])))):''}}</span>
          <div v-else>
            <el-button v-for="(it,i) in tableOperation" :key="'font'+i"
              v-show="!it.icon&&(it.list?it.list[scope.row[it.mark]]:it.name)"
              @click="handlePageOperation(scope.row,it.mark,scope.$index)" size="mini" class="themeBtn">
              {{it.list?it.list[scope.row[it.mark]]:it.name}}</el-button>
            <el-button :title="it.name" v-for="(it,i) in tableOperation" :key="'icon'+i"
              v-show="it.icon&&(it.list?it.list[scope.row[it.mark]]:it.mark)"
              :icon="'el-icon-'+(it.list?it.list[scope.row[it.mark]]:it.mark)" circle
              @click="handlePageOperation(scope.row,it.mark,scope.$index)" size="mini" class="themeBtn"></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination v-show="tablePagination.show" @size-change="pageSizeChange" @current-change="currentPageChange"
      :current-page="tablePagination.current" :page-sizes="[10, 20, 50, 100]" :page-size="tablePagination.size"
      background layout="total, sizes, prev, pager, next, jumper" :total="tablePagination.total"></el-pagination> -->


  </div>
</template>

<script>
  import PagesTable from "../../components/PagesTable.vue";
  export default {
    components: {
      PagesTable
    },
    data() {
      return {
        tableHeight: "",
        search: { //搜索条件
          meterID: "",
          name: "",
          phone: "",
          meterTypeID: "",
          waterRateID: "",
          status: "", //1和0
          meterReaderID: "",
          villageID: "",
          tradeTypeID: "",
          userMeterTypeID: "", //户表类型（单表/多表）
          volumeID: "", //册号
          meterReadTypeID: "", //0=估抄，1=正常，-1=倒表
          meterReadCycleID: "", //1=单月    2=双月    0=每月
          costTypeID: "", //缴费方式
          time: ["", ""], //开始和结束时间
          startTime: "", //格式 yyyy-MM-dd
          endTime: "", //格式 yyyy-MM-dd
        },
        devTypeList: [{
          meterTypeID: "",
          meterTypeName: "全部"
        }],
        waterRateList: [{
          waterRateName: "生活用水",
          waterRateID: "1"
        }, {
          waterRateName: "居民用水",
          waterRateID: "2"
        }, {
          waterRateName: "特种用水",
          waterRateID: "3"
        }, {
          waterRateName: "非居民用水",
          waterRateID: "4"
        }, {
          waterRateName: "非生活用水",
          waterRateID: "5"
        }],
        statusList: [{
          id: "",
          name: "全部"
        }, {
          id: "1",
          name: "正常"
        }, {
          id: "0",
          name: "停用"
        }],
        meterReaderList: [{
          meterReaderID: "",
          name: "全部"
        }],
        tradeTypeList: [{
            tradeTypeID: 1,
            tradeTypeName: "默认"
          },
          {
            tradeTypeID: 4,
            tradeTypeName: "餐饮"
          },
          {
            tradeTypeID: 5,
            tradeTypeName: "住宿"
          },
          {
            tradeTypeID: 6,
            tradeTypeName: "美容美发"
          },
          {
            tradeTypeID: 7,
            tradeTypeName: "洗浴"
          },
          {
            tradeTypeID: 8,
            tradeTypeName: "洗车"
          },
          {
            tradeTypeID: 9,
            tradeTypeName: "普通商店"
          }
        ],
        cycleAmountList: [{
            meterReadCycleID: 0,
            meterReadCycleName: "每月"
          },
          {
            meterReadCycleID: 1,
            meterReadCycleName: "单月"
          },
          {
            meterReadCycleID: 2,
            meterReadCycleName: "双月"
          }
        ],
        typeAmountList: [{
            id: "0",
            name: "估抄"
          },
          {
            id: "1",
            name: "正常"
          },
          {
            id: "-1",
            name: "倒表"
          }
        ],
        costTypeList: [{
          costTypeID: "",
          costTypeName: "全部"
        }],
        userAddrList: [{
            villageName: "新华巷",
            villageID: 28
          },
          {
            villageName: "朝阳路东",
            villageID: 29
          },
          {
            villageName: "朝阳路西",
            villageID: 32
          },
          {
            villageName: "党校后",
            villageID: 33
          },
          {
            villageName: "鸳鸯楼",
            villageID: 34
          },
          {
            villageName: "人大单元楼",
            villageID: 35
          },
          {
            villageName: "老干部单元楼",
            villageID: 36
          },
          {
            villageName: "水泉崖",
            villageID: 38
          },
          {
            villageName: "民政局宿舍",
            villageID: 40
          },
          {
            villageName: "总表（吴）",
            villageID: 41
          },
          {
            villageName: "富康家园",
            villageID: 42
          },
          {
            villageName: "教委单元楼",
            villageID: 45
          },
          {
            villageName: "德和盛嘉园",
            villageID: 95
          }
        ],
        userAddrListCopy: [{
            villageName: "新华巷",
            villageID: 28
          },
          {
            villageName: "朝阳路东",
            villageID: 29
          },
          {
            villageName: "朝阳路西",
            villageID: 32
          },
          {
            villageName: "党校后",
            villageID: 33
          },
          {
            villageName: "鸳鸯楼",
            villageID: 34
          },
          {
            villageName: "人大单元楼",
            villageID: 35
          },
          {
            villageName: "老干部单元楼",
            villageID: 36
          },
          {
            villageName: "水泉崖",
            villageID: 38
          },
          {
            villageName: "民政局宿舍",
            villageID: 40
          },
          {
            villageName: "总表（吴）",
            villageID: 41
          },
          {
            villageName: "富康家园",
            villageID: 42
          },
          {
            villageName: "教委单元楼",
            villageID: 45
          },
          {
            villageName: "德和盛嘉园",
            villageID: 95
          }
        ],
        userMeterTypeList: [{
            userMeterTypeID: 1,
            userMeterTypeName: "单表用户"
          },
          {
            userMeterTypeID: 2,
            userMeterTypeName: "多表用户"
          },
          {
            userMeterTypeID: 3,
            userMeterTypeName: "单表混合"
          },
          {
            userMeterTypeID: 4,
            userMeterTypeName: "多表混合"
          }
        ],
        volumeList: [],
        // tableSpan: {
        //   mark: "userID",
        //   colsIndex: [0, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18]
        // },
        tableHeader: [
          // {
          //   name: "用户编号",
          //   mark: "userID",
          //   minWidth: "80",
          //   fixed: true,
          // },
          {
            name: "用户编号",
            mark: "meterID",
            minWidth: "70",
            fixed: true,
          },
          {
            name: "用户姓名",
            mark: "name",
            minWidth: "90",
            fixed: true,
          },
          {
            name: "所属册",
            mark: "volumeName",
            minWidth: "100"
          },
          {
            name: "小区",
            mark: "villageName",
            minWidth: "140"
          },
          {
            name: "详细地址",
            mark: "villageDetail",
            minWidth: "140"
          },
          {
            name: "联系方式",
            mark: "pns",
            minWidth: "120"
          },
          {
            name: "人口数",
            mark: "peopleNum",
            minWidth: "70"
          },

          {
            name: "行业类型",
            mark: "tradeTypeName",
            minWidth: "90"
          },
          {
            name: "抄表周期",
            mark: "meterReadCycleName",
            minWidth: "90"
          },
          {
            name: "预存金额",
            mark: "depositMoney",
            minWidth: "90"
          },



          {
            name: "用水类型",
            mark: "waterRateName",
            minWidth: "90"
          },
          {
            name: "设备类型",
            mark: "meterTypeName",
            minWidth: "90"
          },
          {
            name: "抄表类型",
            mark: "meterReadTypeName",
            minWidth: "90"
          },
          {
            name: "上期底数",
            mark: "lastReadingValue",
            minWidth: "90"
          },
          {
            name: "本期底数",
            mark: "currReadingValue",
            minWidth: "90"
          },
          // {
          //   name: "安装位置",
          //   mark: "location",
          //   minWidth: "90"
          // },
          {
            name: "状态",
            mark: "status",
            minWidth: "50",
            list: {
              "-1": "注销",
              0: "停用",
              1: "正常",
            },
            marks: "status",
            color: {
              "-1": "red",
              0: "red",
              1: "green"
            },
            fixed: "right",
          },
          {
            name: "操作",
            mark: "",
            minWidth: "90",
            fixed: "right",
          }
        ],
        tableOperation: [{
          name: "停用/启用",
          mark: "status",
          list: {
            1: "close",
            0: "check"
          },
          icon: true
        }, {
          name: "销户",
          mark: "delete",
          icon: true
        }],
        tablePagination: {
          show: true,
          current: 1,
          size: 10,
          total: 4
        },
        tableData: [{
            "readerName": "\u767d\u660e\u5e38",
            "shopname": "",
            "lastReadingTime": "1970-01-01 00:00:00",
            "volumeName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "currReadingValue": 513,
            "waterWell": "",
            "meterReadTypeName": "\u6b63\u5e38",
            "villageName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "meterTypeName": "\u673a\u68b0\u6c34\u8868",
            "userMeterTypeName": "\u5355\u8868\u7528\u6237",
            "meterReadTypeID": 1,
            "userID": 1,
            "meterTypeID": 1,
            "meterStatus": 1,
            "meterID": 1,
            "depositMoney": 0.0,
            "status": 1,
            "caliber": 15,
            "pns": "13099046355-\u9ed8\u8ba4",
            "waterRateID": 1,
            "meterReadCycleName": "\u5355\u6708",
            "tradeTypeName": "\u9ed8\u8ba4",
            "extMK": "",
            "costTypeName": "\u73b0\u91d1/\u5fae\u4fe1\u652f\u4ed8",
            "meterCreateTime": "2013-03-19 00:00:00",
            "waterRateName": "\u751f\u6d3b\u7528\u6c34",
            "currMeterReadingRecordStatus": 3,
            "name": "\u767d\u79c0\u73cd",
            "tradeTypeID": 1,
            "createSysuser": "\u738b\u6811\u6797",
            "peopleNum": 4,
            "lastReadingValue": 513,
            "villageDetail": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "aliasName": "",
            "contractID": "1901"
          },
          {
            "readerName": "\u767d\u660e\u5e38",
            "shopname": "",
            "lastReadingTime": "2020-07-09 00:00:00",
            "volumeName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "currReadingValue": 1288,
            "waterWell": "",
            "meterReadTypeName": "\u6b63\u5e38",
            "villageName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "meterTypeName": "\u673a\u68b0\u6c34\u8868",
            "userMeterTypeName": "\u5355\u8868\u7528\u6237",
            "meterReadTypeID": 1,
            "userID": 2,
            "meterTypeID": 1,
            "meterStatus": 1,
            "meterID": 2,
            "depositMoney": 0.0,
            "status": 1,
            "caliber": 15,
            "pns": "13546317653-\u9ed8\u8ba4",
            "waterRateID": 1,
            "meterReadCycleName": "\u5355\u6708",
            "tradeTypeName": "\u9ed8\u8ba4",
            "extMK": "",
            "costTypeName": "\u73b0\u91d1/\u5fae\u4fe1\u652f\u4ed8",
            "meterCreateTime": "2013-03-19 00:00:00",
            "waterRateName": "\u751f\u6d3b\u7528\u6c34",
            "currMeterReadingRecordStatus": 3,
            "name": "\u8fb9\u5cf0\u79c0",
            "tradeTypeID": 1,
            "createSysuser": "\u738b\u6811\u6797",
            "peopleNum": 3,
            "lastReadingValue": 1288,
            "villageDetail": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d1\u63922\u53f7",
            "aliasName": "",
            "contractID": "1902"
          },
          {
            "readerName": "\u767d\u660e\u5e38",
            "shopname": "",
            "lastReadingTime": "2021-03-25 17:25:20",
            "volumeName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "currReadingValue": 588,
            "waterWell": "",
            "meterReadTypeName": "\u6b63\u5e38",
            "villageName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "meterTypeName": "\u673a\u68b0\u6c34\u8868",
            "userMeterTypeName": "\u5355\u8868\u7528\u6237",
            "meterReadTypeID": 1,
            "userID": 3,
            "meterTypeID": 1,
            "meterStatus": 1,
            "meterID": 3,
            "depositMoney": 3.75,
            "status": 1,
            "caliber": 15,
            "pns": "15935619588-\u9ed8\u8ba4",
            "waterRateID": 1,
            "meterReadCycleName": "\u5355\u6708",
            "tradeTypeName": "\u9ed8\u8ba4",
            "extMK": "",
            "costTypeName": "\u73b0\u91d1/\u5fae\u4fe1\u652f\u4ed8",
            "meterCreateTime": "2013-03-19 00:00:00",
            "waterRateName": "\u751f\u6d3b\u7528\u6c34",
            "currMeterReadingRecordStatus": 3,
            "name": "\u5218\u5b58\u62f4",
            "tradeTypeID": 1,
            "createSysuser": "\u738b\u6811\u6797",
            "peopleNum": 3,
            "lastReadingValue": 543,
            "villageDetail": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "aliasName": "",
            "contractID": "1903"
          },
          {
            "readerName": "\u767d\u660e\u5e38",
            "shopname": "",
            "lastReadingTime": "1970-01-01 00:00:00",
            "volumeName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "currReadingValue": 720,
            "waterWell": "",
            "meterReadTypeName": "\u6b63\u5e38",
            "villageName": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "meterTypeName": "\u673a\u68b0\u6c34\u8868",
            "userMeterTypeName": "\u5355\u8868\u7528\u6237",
            "meterReadTypeID": 1,
            "userID": 4,
            "meterTypeID": 1,
            "meterStatus": 1,
            "meterID": 4,
            "depositMoney": 1.8,
            "status": 1,
            "caliber": 15,
            "pns": "13593177167-\u9ed8\u8ba4",
            "waterRateID": 1,
            "meterReadCycleName": "\u5355\u6708",
            "tradeTypeName": "\u9ed8\u8ba4",
            "extMK": "",
            "costTypeName": "\u73b0\u91d1/\u5fae\u4fe1\u652f\u4ed8",
            "meterCreateTime": "2013-03-19 00:00:00",
            "waterRateName": "\u751f\u6d3b\u7528\u6c34",
            "currMeterReadingRecordStatus": 3,
            "name": "\u5f20\u83b2\u82b1",
            "tradeTypeID": 1,
            "createSysuser": "\u77f3\u6167\u73b2",
            "peopleNum": 3,
            "lastReadingValue": 0,
            "villageDetail": "\u65b0\u534e\u4e66\u5e97\u5bbf\u820d",
            "aliasName": "",
            "contractID": "1904"
          }
        ],
        tableDataAll: [],
        searchAllParam: {}
      }
    },
    mounted() {
      // this.initData();
    },
    beforeDestroy() {},
    created() {
      var self = this;
      var height = $(document).height() - 172 - 205 - 50;
      self.tableHeight = height + "";
    },
    methods: {
      async initData() {
        await this.getAllTypes();
        // await this.getDevType();
        // await this.getWaterRate();
        // await this.getMeterReader();
        // await this.getTradeType();
        // await this.getCostType();
        // await this.getReadCycle();
        // await this.getReadType();
        // await this.getVillage();
        this.getData();

        //temp

        // this.$axios.post("/service/bsMeterReadCycleGet").then(res => {})
      },
      villageFilter(txt) {
        //对绑定数据赋值
        this.userAddrList = this.userAddrListCopy.filter((item) => {
          if (item.villageName.indexOf(txt) !== -1 || item.sx.indexOf(txt) !== -1 || item.qp.indexOf(txt) !== -1) {
            return true
          }
        })
      },
      getData() { //获取用户列表
        const self = this;
        var param = {
          name: self.search.name,
          phone: self.search.phone,
          meterID: self.search.meterID,
          waterRateID: self.search.waterRateID,
          tradeTypeID: self.search.tradeTypeID,
          userMeterTypeID: self.search.userMeterTypeID,
          costTypeID: self.search.costTypeID,
          meterReadCycleID: self.search.meterReadCycleID,
          volumeID: self.search.volumeID,
          villageID: self.search.villageID,
          status: self.search.status,
          // meterTypeID: self.search.meterTypeID,
          // waterRateID: self.search.waterRateID,
          // status:self.search.status,
          // meterReaderID:self.search.meterReaderID,
          // villageID: self.search.villageID,
          // tradeTypeID:self.search.tradeTypeID,
          // meterReadTypeID:self.search.meterReadTypeID,
          // meterReadCycleID:self.search.meterReadCycleID,
          // costTypeID:self.search.costTypeID,
          // startTime:self.search.time?self.search.time[0]:"",
          // endTime:self.search.time?self.search.time[1]:"",

          pageNum: self.tablePagination.current, //页码
          pageSize: self.tablePagination.size, //条数
        }
        self.searchAllParam = {}
        self.$axios.post("/service/bsMeterUsersGet", param).then(res => {
          if (res.data.status === "success") {
            var temp = res.data.res;
            self.tableData = temp
            self.tablePagination.total = res.data.totalNum
            self.searchAllParam = {
              name: self.search.name,
              phone: self.search.phone,
              meterID: self.search.meterID,
              waterRateID: self.search.waterRateID,
              tradeTypeID: self.search.tradeTypeID,
              userMeterTypeID: self.search.userMeterTypeID,
              costTypeID: self.search.costTypeID,
              meterReadCycleID: self.search.meterReadCycleID,
              volumeID: self.search.volumeID,
              villageID: self.search.villageID,
              status: self.search.status,
              pageNum: 1, //页码
              pageSize: self.tablePagination.total, //条数
            }
            self.getSpanArr(self.tableData);
          } else {
            self.$message.error(res.data.res);
          }
        });
      },
      pageSizeChange(data) {
        const self = this
        self.tablePagination.size = data
        self.getData()
      },
      currentPageChange(data) {
        const self = this
        self.tablePagination.current = data
        self.getData()
      },
      handlePageOperation(row, mark) {
        const self = this;
        if (mark == "edit") {
          //给表单赋值......
        } else if (mark == "delete") {
          this.$confirm('确定要删除此用户吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.delectById(row.userID);
          }).catch(() => {});
        } else if (mark == "status") {
          this.$confirm('确定要修改此用户状态吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            var status = row.status == 0 ? 1 : 0;
            this.editStatusById(row.userID, status);
          }).catch(() => {});
        }
      },
      editStatusById(userID, status) {
        const self = this;
        var param = {
          userID: userID,
          status: status
        }
        self.$axios.post("/service/bsMeterUserStatusMod", param).then(res => {
          if (res.data.status === "success") {
            self.$message({
              type: 'success',
              message: "操作成功！"
            });
            //刷新数据
            self.getData();
          } else {
            self.$message.error(res.data.res);
          }
        });
      },
      delectById(id) {
        const self = this;
        var param = {
          userID: id
        };
        // self.$axios.post("/service/bsMeterUserDel", param).then(res => {
        //   if (res.data.status === "success") {
        //     self.$message(res.data.res);
        //     self.getData();
        //   } else {
        //     self.$message(res.data.res);
        //   }
        // });

        //销户
        self.$axios.post("/service/bsMeterUserUnsubscribe", param).then(res => {
          if (res.data.status === "success") {
            self.$message.success(res.data.res);
            self.getData();
          } else {
            self.$message.error(res.data.res);
          }
        });
      },
      getSpanArr(data) {
        this.spanArr = [];
        for (var i = 0; i < data.length; i++) {
          if (i === 0) {
            this.spanArr.push(1);
            this.pos = 0;
          } else {
            // 判断当前元素与上一个元素是否相同,因合并第一个所以[0]
            if (data[i].userID === data[i - 1].userID) {
              this.spanArr[this.pos] += 1;
              this.spanArr.push(0);
            } else {
              this.spanArr.push(1);
              this.pos = i;
            }
          }
        }
      },
      objectSpanMethod({
        row,
        column,
        rowIndex,
        columnIndex
      }) {
        var colsIndex = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, (this.tableHeader.length - 1)]
        if (colsIndex.includes(columnIndex)) {
          const _row = this.spanArr[rowIndex];
          const _col = _row > 0 ? 1 : 0;
          return {
            rowspan: _row,
            colspan: _col
          };
        }

      },
      async getAllTypes() { //获取全部基础数据列表
        const self = this;
        var param = {
          types: "all"
        }
        self.$axios.post("/service/bsSelectListGet", param).then(res => {
          if (res.data.status === "success") {
            var tmp = res.data.res;
            //设备类型列表
            self.devTypeList = self.devTypeList.concat(tmp.meterType)
            //水价类型列表
            self.waterRateList = self.waterRateList.concat(tmp.waterRate)
            //用户行业类型
            self.tradeTypeList = self.tradeTypeList.concat(tmp.tradeType)
            //缴费方式
            self.costTypeList = self.costTypeList.concat(tmp.costType)
            //抄表周期
            self.cycleAmountList = tmp.meterReadCycle
            //倒表估抄
            self.typeAmountList = tmp.meterReadType
            //小区
            self.userAddrList = self.userAddrList.concat(tmp.village)
            //保留数据源
            self.userAddrListCopy = Object.assign(self.userAddrList);
            //户表类型
            self.userMeterTypeList = tmp.userMeterType
            //册号
            self.volumeList = tmp.volume
          } else {
            self.$message(res.data.res);
          }
        });
      },
      // async test() { //test
      //   const self = this;
      //   var param = {
      //     currValue: 10,
      //     meterID: 28,
      //   }
      //   self.$axios.post("/service/bsMeterReadingSubmit", param).then(res => {
      //     if (res.data.status === "success") {

      //     } else {
      //       self.$message(res.data.res);
      //     }
      //   });
      // },
      async getDevType() { //设备类型列表
        const self = this;
        self.$axios.post("/service/bsMeterTypeGet").then(res => {
          if (res.data.status === "success") {
            self.devTypeList = self.devTypeList.concat(res.data.res)
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getWaterRate() { //水价类型列表
        const self = this;
        self.$axios.post("/service/bsWaterRateGet").then(res => {
          if (res.data.status === "success") {
            self.waterRateList = self.waterRateList.concat(res.data.res)
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getMeterReader() { //抄表员
        const self = this;
        var param = {
          rid: 3
        }
        self.$axios.post("/service/bsMeterReaderGet", param).then(res => {
          if (res.data.status === "success") {
            self.meterReaderList = self.meterReaderList.concat(res.data.res)
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getTradeType() { //用户行业类型
        const self = this;
        self.$axios.post("/service/bsMeterUserTradeTypeGet").then(res => {
          if (res.data.status === "success") {
            self.tradeTypeList = self.tradeTypeList.concat(res.data.res)
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getCostType() { //缴费方式
        const self = this;
        self.$axios.post("/service/bsMeterUserCostTypeGet").then(res => {
          if (res.data.status === "success") {
            self.costTypeList = self.costTypeList.concat(res.data.res)
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getReadCycle() { //抄表周期
        const self = this;
        self.$axios.post("/service/bsMeterReadCycleGet").then(res => {
          if (res.data.status === "success") {
            self.cycleAmountList = res.data.res
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getReadType() { //其他条件，倒表...
        const self = this;
        self.$axios.post("/service/bsMeterReadTypeGet").then(res => {
          if (res.data.status === "success") {
            self.typeAmountList = res.data.res
          } else {
            self.$message(res.data.res);
          }
        });
      },
      async getVillage() { //获取所有小区
        const self = this;
        self.$axios.post("/service/bsVillageGet").then(res => {
          if (res.data.status === "success") {
            self.userAddrList = self.userAddrList.concat(res.data.res)
          } else {
            self.$message(res.data.res);
          }
        });
      },
      getTableAllData(text) {
        var self = this;
        self.$axios
          .post("/service/bsMeterUsersGet", self.searchAllParam)
          .then(res => {
            if (res.data.status === "success") {
              if (text == 'export') {
                self.$refs.child.exportAllToExcel(res.data.res);
              } else if (text == 'print') {
                self.$refs.child.printAllData(res.data.res);
              }
            } else {
              self.$message.error(res.data.res);
            }
          });
      }
    }
  }
</script>
<style lang="scss" scoped>

</style>